Libraries:

# libraries -------------------
library(ggplot2)
library(vegan)
library(ggvegan)
library(tidyverse)
library(ggordiplots)

Set working directory

knitr::opts_knit$set(root.dir = '/Users/user/Desktop/Data/Regen_RProj/')

Functions:

# functions -------------------

Source, tranform, select, and relativize MA & LI veg data (hidden)

Species found in at least 5% (11 plots) of plots in Coastal Barrens are: VAPA, GABA, QUIL, GAPR, VAAN, PTAQ, QUCO, PIRI, KAAN, MELI, RUSP, CAPE, QUAL, SMGL, & QUPR

Source and transform envr & categorical data; merge for predictor df to compare nmds against (hidden)

Run NMDS

# 3 dimensions
mali_3d <- metaMDS(rel_mali5,
                   distance = 'bray',
                   k = 3,
                   trymax = 20,
                   autotransform = FALSE)
## Run 0 stress 0.1272962 
## Run 1 stress 0.1275737 
## ... Procrustes: rmse 0.03483256  max resid 0.1276668 
## Run 2 stress 0.1272962 
## ... Procrustes: rmse 6.488934e-05  max resid 0.0001360758 
## ... Similar to previous best
## Run 3 stress 0.1272958 
## ... New best solution
## ... Procrustes: rmse 0.0005253442  max resid 0.001722101 
## ... Similar to previous best
## Run 4 stress 0.1275736 
## ... Procrustes: rmse 0.0349418  max resid 0.1277384 
## Run 5 stress 0.127296 
## ... Procrustes: rmse 0.0003137195  max resid 0.0009846064 
## ... Similar to previous best
## Run 6 stress 0.1275744 
## ... Procrustes: rmse 0.03515513  max resid 0.1283886 
## Run 7 stress 0.1272962 
## ... Procrustes: rmse 0.0004673627  max resid 0.001530335 
## ... Similar to previous best
## Run 8 stress 0.127574 
## ... Procrustes: rmse 0.03505945  max resid 0.1280689 
## Run 9 stress 0.1272959 
## ... Procrustes: rmse 0.0003613979  max resid 0.001161943 
## ... Similar to previous best
## Run 10 stress 0.127339 
## ... Procrustes: rmse 0.004398584  max resid 0.01252862 
## Run 11 stress 0.1272964 
## ... Procrustes: rmse 0.0006334705  max resid 0.002058005 
## ... Similar to previous best
## Run 12 stress 0.127296 
## ... Procrustes: rmse 0.000374428  max resid 0.001245465 
## ... Similar to previous best
## Run 13 stress 0.127296 
## ... Procrustes: rmse 0.0004134038  max resid 0.001345558 
## ... Similar to previous best
## Run 14 stress 0.1275738 
## ... Procrustes: rmse 0.03499376  max resid 0.1279014 
## Run 15 stress 0.1275734 
## ... Procrustes: rmse 0.03480174  max resid 0.1273162 
## Run 16 stress 0.1272958 
## ... Procrustes: rmse 0.0001577471  max resid 0.0004415243 
## ... Similar to previous best
## Run 17 stress 0.1272959 
## ... Procrustes: rmse 0.0003511021  max resid 0.001130468 
## ... Similar to previous best
## Run 18 stress 0.127296 
## ... Procrustes: rmse 0.0003421706  max resid 0.001046611 
## ... Similar to previous best
## Run 19 stress 0.1272959 
## ... Procrustes: rmse 0.0003309755  max resid 0.001078816 
## ... Similar to previous best
## Run 20 stress 0.127296 
## ... Procrustes: rmse 0.0004191826  max resid 0.001361881 
## ... Similar to previous best
## *** Best solution repeated 12 times
# converges, stress of 0.127 - 0.128

set.seed(2)
# 2 dimensions
mali_2d <- metaMDS(rel_mali5, 
                   distance = 'bray', 
                   k = 2,
                   try = 40,
                   trymax = 40,
                   autotransform = FALSE)
## Run 0 stress 0.2013098 
## Run 1 stress 0.2421891 
## Run 2 stress 0.2164813 
## Run 3 stress 0.2248403 
## Run 4 stress 0.2013098 
## ... New best solution
## ... Procrustes: rmse 7.336217e-05  max resid 0.0002404534 
## ... Similar to previous best
## Run 5 stress 0.2166909 
## Run 6 stress 0.2013098 
## ... Procrustes: rmse 2.20954e-05  max resid 7.187511e-05 
## ... Similar to previous best
## Run 7 stress 0.2299679 
## Run 8 stress 0.2334747 
## Run 9 stress 0.2067192 
## Run 10 stress 0.2063475 
## Run 11 stress 0.2248403 
## Run 12 stress 0.2052525 
## Run 13 stress 0.2013098 
## ... Procrustes: rmse 8.623799e-05  max resid 0.0002840637 
## ... Similar to previous best
## Run 14 stress 0.2248403 
## Run 15 stress 0.2013098 
## ... Procrustes: rmse 7.687422e-05  max resid 0.0002349284 
## ... Similar to previous best
## Run 16 stress 0.2385195 
## Run 17 stress 0.2378598 
## Run 18 stress 0.2013098 
## ... Procrustes: rmse 7.160904e-05  max resid 0.0002354649 
## ... Similar to previous best
## Run 19 stress 0.240332 
## Run 20 stress 0.271914 
## Run 21 stress 0.2063472 
## Run 22 stress 0.2013098 
## ... Procrustes: rmse 3.826719e-05  max resid 9.76465e-05 
## ... Similar to previous best
## Run 23 stress 0.2337596 
## Run 24 stress 0.2518641 
## Run 25 stress 0.2401184 
## Run 26 stress 0.2013098 
## ... Procrustes: rmse 6.309312e-06  max resid 1.438008e-05 
## ... Similar to previous best
## Run 27 stress 0.2431912 
## Run 28 stress 0.2013098 
## ... Procrustes: rmse 2.79146e-06  max resid 8.73469e-06 
## ... Similar to previous best
## Run 29 stress 0.2076391 
## Run 30 stress 0.2013099 
## ... Procrustes: rmse 0.0001601721  max resid 0.0005288505 
## ... Similar to previous best
## Run 31 stress 0.2013098 
## ... Procrustes: rmse 2.72951e-05  max resid 6.009303e-05 
## ... Similar to previous best
## Run 32 stress 0.2185542 
## Run 33 stress 0.2248403 
## Run 34 stress 0.2248403 
## Run 35 stress 0.239287 
## Run 36 stress 0.2248403 
## Run 37 stress 0.2076443 
## Run 38 stress 0.2394146 
## Run 39 stress 0.2013098 
## ... Procrustes: rmse 1.065455e-05  max resid 3.451836e-05 
## ... Similar to previous best
## Run 40 stress 0.2013098 
## ... Procrustes: rmse 2.107096e-05  max resid 6.965666e-05 
## ... Similar to previous best
## *** Best solution repeated 12 times
# stress still too high to represent in 2 dimensions, lowest is ~ 0.2

rm(mali_2d)

Make correlation data for bi-plots

ma.veg_enr <- envfit(mali_3d, ma.meta.data_veg)
ma.veg_spc.envr <- envfit(mali_3d, rel_mali5)

# site data -------------------
ma.site.scrs <- as.data.frame(scores(mali_3d, display = "sites"))

ma.site.scrs <- cbind(ma.site.scrs, Treat_Type = ma.meta.data_veg$Treat_Type)
ma.site.scrs <- cbind(ma.site.scrs, Region = ma.meta.data_veg$Region)

# species data   -------------------
ma.spp.scrs <- as.data.frame(scores(ma.veg_spc.envr, display = "vectors"))
ma.spp.scrs <- cbind(ma.spp.scrs, Species = rownames(ma.spp.scrs))
ma.spp.scrs <- cbind(ma.spp.scrs, pval = ma.veg_spc.envr$vectors$pvals)

sig.ma_spp.scrs <- subset(ma.spp.scrs, pval<=0.05)

print(sig.ma_spp.scrs)
##            NMDS1       NMDS2 Species  pval
## GAPR -0.43289143 -0.36587410    GAPR 0.028
## VAAN -0.58551134  0.23703707    VAAN 0.003
## QUCO  0.47180138  0.31533695    QUCO 0.009
## PIRI -0.09462897  0.63997182    PIRI 0.001
## KAAN -0.64354347  0.04959082    KAAN 0.001
## MELI -0.21628313 -0.54629722    MELI 0.003
## RUSP -0.62463981  0.06725552    RUSP 0.004
## SMGL  0.06339300  0.74447942    SMGL 0.001
## QUPR -0.58253269 -0.08858672    QUPR 0.012
# create species vectors for indicator species -------------------
mali.ind.spp <- ma.spp.scrs %>% 
  filter(Species %in% c('QUPR', "KAAN", "RUSP", "SMGL"))

# envr data -------------------
ma.envr.scrs <- as.data.frame(scores(ma.veg_enr, display = "vectors"))
ma.envr.scrs <- cbind(ma.envr.scrs, env.variables = rownames(ma.envr.scrs))
ma.envr.scrs <- cbind(ma.envr.scrs, pval = ma.veg_enr$vectors$pvals)
ma.sig_envr.scrs <- subset(ma.envr.scrs, pval<=0.05)

print(ma.sig_envr.scrs)
##                 NMDS1      NMDS2 env.variables  pval
## Moss       -0.1484848  0.5470842          Moss 0.011
## BA_HA       0.5192504 -0.3901547         BA_HA 0.004
## PIRI.BA_HA  0.5939880 -0.4423550    PIRI.BA_HA 0.001
ma.sig_envr.scrs <- ma.sig_envr.scrs %>% 
  filter(env.variables != "BA_HA")

Significant species are: GAPR, VAAN, QUCO, PIRI, KAAN, MELI, RUSP, SMGL, QUPR

Significant environmental factors are: Moss, Basal area per hectare, and PIRI basal area per hectare.

I’m only going to keep one BA measure; PIRI has a lower p value, so thinking that one, but open to other ideas.

This is a 3D ordination being represented by 2D

Using the first two axes, which represent the most variation in the ordination space

library(plotly)

fort.mali3 <- fortify(mali_3d) %>% 
  filter(score == "sites")

plot_ly(x = fort.mali3$NMDS1, y = fort.mali3$NMDS2, z= fort.mali3$NMDS3, type = "scatter3d", mode = "markers", color = ma.meta.data_veg$Treat_Type, )
# Here is a 3D plot, just to show

stressplot(mali_3d)

ordicloud(mali_3d)

GG plot

# based on the idea that NMDS scores express the highest variation in first axis and on down, I will plot the 1st two and take a look -------------------
# control = yellow, fallrx = dark green, harvest = beige, mowrx = light green, spring rx = red

colors = c("#D8B70A", "#02401B", "#A2A475", "#81A88D", "#972D15")

# create ellipse plot -------------------
mali.plot.e <- gg_ordiplot(mali_3d, groups = ma.meta.data_veg$Treat_Type)

# pull out ellipse data -------------------
ellipse.mali <- fortify(mali.plot.e$df_ellipse) %>% 
  group_by(Group)

# base plot -------------------
ma.nmds.plot <-  ggplot(ma.site.scrs, aes(x=NMDS1, y=NMDS2))+
  geom_point(aes(NMDS1, NMDS2, colour = factor(ma.site.scrs$Treat_Type), shape = factor(ma.site.scrs$Region)), size = 2)+
  scale_color_manual(values =  c("#D8B70A", "#02401B", "#A2A475", "#81A88D", "#972D15"))+
  coord_fixed()+
  theme_classic()+
  theme(panel.background = element_blank()) +
  labs(colour = "Treatment Type", shape = "Region")+
  theme(legend.position = "right", legend.text = element_text(size = 12), legend.title = element_text(size = 12), axis.text = element_text(size = 10))

# plot with ellipse -------------------
ma.nmds.plot + 
  geom_path(data = ellipse.mali, aes(x=x, y=y, color=Group),  linejoin = "round", show.legend = FALSE)+
  labs(title = "Coastal barrens ordination \n (Axes 1 & 2")+
  theme(plot.title=element_text(hjust=0.5, size=20))

# add significant species -------------------
ma.nmds.plot +
  geom_path(data = ellipse.mali, aes(x=x, y=y, color=Group),  linejoin = "round", show.legend = FALSE)+
  geom_segment(data = sig.ma_spp.scrs, aes(x=0, xend=NMDS1, y=0, yend=NMDS2), arrow = arrow(length = unit(0.25, "cm")), colour = "grey10", lwd = 0.3)+
  ggrepel::geom_text_repel(data = sig.ma_spp.scrs, aes(x=NMDS1, y=NMDS2, label = Species), cex = 3, direction = "both", segment.size = 0.25)+
  labs(title = "Coastal barrens ordination with \n significant species (Axes 1 & 2)")+
  theme(plot.title=element_text(hjust=0.5, size=20))

# add indicators species -------------------
ind.sp.mali_color <- c("QUPR" = "#81A88D", "KAAN" = "#81A88D", "SMGL" = "#A2A475", "RUSP" = "#81A88D")

ma.nmds.plot +
  geom_path(data = ellipse.mali, aes(x=x, y=y, color=Group),  linejoin = "round", show.legend = FALSE)+
  geom_segment(data = mali.ind.spp, aes(x=0, xend=NMDS1, y=0, yend=NMDS2), arrow = arrow(length = unit(0.25, "cm")), colour = ind.sp.mali_color, lwd = 0.75)+
  ggrepel::geom_text_repel(data = mali.ind.spp, aes(x=NMDS1, y=NMDS2, label = Species), cex = 3, direction = "both", segment.size = 0.25)+
  labs(title = "Coastal barrens ordination with \n indicator species (Axes 1 & 2)")+
  theme(plot.title=element_text(hjust=0.5, size=20))

# add significant envr factors -------------------

ma.nmds.plot +
  geom_path(data = ellipse.mali, aes(x=x, y=y, color=Group),  linejoin = "round", show.legend = FALSE)+
  geom_segment(data = ma.sig_envr.scrs, aes(x = 0, xend = NMDS1, y = 0, yend=NMDS2), arrow = arrow(length = unit(0.25, "cm")))+
  ggrepel::geom_text_repel(data = ma.sig_envr.scrs, aes(x=NMDS1, y=NMDS2, label = env.variables), cex = 4, direction = "both", segment.size = 0.25) +
  labs(title = "Coastal barrens ordination with \n environmental vectors (Axes 1 & 2)")+
  theme(plot.title=element_text(hjust=0.5, size=20))

Plot with significant species & envr factors

ma.nmds.plot +
  geom_path(data = ellipse.mali, aes(x=x, y=y, color=Group),  linejoin = "round", show.legend = FALSE)+
  geom_segment(data = sig.ma_spp.scrs, aes(x=0, xend=NMDS1, y=0, yend=NMDS2), arrow = arrow(length = unit(0.25, "cm")), colour = "grey10", lwd = 0.3)+
  ggrepel::geom_text_repel(data = sig.ma_spp.scrs, aes(x=NMDS1, y=NMDS2, label = Species), cex = 3, direction = "both", segment.size = 0.25)+
  geom_segment(data = mali.ind.spp, aes(x=0, xend=NMDS1, y=0, yend=NMDS2), arrow = arrow(length = unit(0.25, "cm")), colour = ind.sp.mali_color, lwd = 0.75)+
  ggrepel::geom_text_repel(data = mali.ind.spp, aes(x=NMDS1, y=NMDS2, label = Species), cex = 3, direction = "both", segment.size = 0.25)+
  labs(title = "Coastal barrens ordination with significant \n species & environmental factors (Axes 1 & 2)")+
  theme(plot.title=element_text(hjust=0.5, size=20))

Plot with indcator species & envr factors

ma.nmds.plot +
  geom_path(data = ellipse.mali, aes(x=x, y=y, color=Group),  linejoin = "round", show.legend = FALSE)+
  geom_segment(data = mali.ind.spp, aes(x=0, xend=NMDS1, y=0, yend=NMDS2), arrow = arrow(length = unit(0.25, "cm")), colour = ind.sp.mali_color, lwd = 0.75)+
  ggrepel::geom_text_repel(data = mali.ind.spp, aes(x=NMDS1, y=NMDS2, label = Species), cex = 3, direction = "both", segment.size = 0.25)+
  geom_segment(data = ma.sig_envr.scrs, aes(x = 0, xend = NMDS1, y = 0, yend=NMDS2), arrow = arrow(length = unit(0.25, "cm")))+
  ggrepel::geom_text_repel(data = ma.sig_envr.scrs, aes(x=NMDS1, y=NMDS2, label = env.variables), cex = 4, direction = "both", segment.size = 0.25) +
  labs(title = "Coastal barrens ordination with indicator \n species & environmental factors (Axes 1 & 2)")+
  theme(plot.title=element_text(hjust=0.5, size=20))

Run PerMANOVA to look at the impacts of region and treatment on community composition

summary(as.factor(ma.meta.data_veg$Treat_Type))
##  Control   FallRx  Harvest    MowRx SpringRx 
##        5        3        6        3        6
ma.tt <- adonis2(rel_mali5 ~ Treat_Type, data = ma.meta.data_veg)

print(ma.tt)
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 999
## 
## adonis2(formula = rel_mali5 ~ Treat_Type, data = ma.meta.data_veg)
##            Df SumOfSqs      R2      F Pr(>F)    
## Treat_Type  4   1.9569 0.31903 2.1082  0.001 ***
## Residual   18   4.1769 0.68097                  
## Total      22   6.1339 1.00000                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Pairwise follow up

library(pairwiseAdonis)

pairwise.adonis2(rel_mali5 ~ Treat_Type, data = ma.meta.data_veg)
## $parent_call
## [1] "rel_mali5 ~ Treat_Type , strata = Null , permutations 999"
## 
## $FallRx_vs_SpringRx
##            Df SumOfSqs      R2      F Pr(>F)
## Treat_Type  1  0.21549 0.10956 0.8613  0.614
## Residual    7  1.75138 0.89044              
## Total       8  1.96687 1.00000              
## 
## $FallRx_vs_MowRx
##            Df SumOfSqs      R2      F Pr(>F)
## Treat_Type  1  0.48859 0.46035 3.4122    0.1
## Residual    4  0.57276 0.53965              
## Total       5  1.06134 1.00000              
## 
## $FallRx_vs_Harvest
##            Df SumOfSqs      R2      F Pr(>F)
## Treat_Type  1  0.40379 0.20243 1.7767  0.109
## Residual    7  1.59094 0.79757              
## Total       8  1.99473 1.00000              
## 
## $FallRx_vs_Control
##            Df SumOfSqs      R2      F Pr(>F)
## Treat_Type  1  0.39033 0.23712 1.8649   0.12
## Residual    6  1.25581 0.76288              
## Total       7  1.64614 1.00000              
## 
## $SpringRx_vs_MowRx
##            Df SumOfSqs      R2      F Pr(>F)  
## Treat_Type  1  0.65697 0.28336 2.7678  0.015 *
## Residual    7  1.66151 0.71664                
## Total       8  2.31848 1.00000                
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## $SpringRx_vs_Harvest
##            Df SumOfSqs      R2      F Pr(>F)  
## Treat_Type  1   0.4952 0.15598 1.8481  0.061 .
## Residual   10   2.6797 0.84402                
## Total      11   3.1749 1.00000                
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## $SpringRx_vs_Control
##            Df SumOfSqs     R2      F Pr(>F)
## Treat_Type  1  0.16729 0.0666 0.6422  0.778
## Residual    9  2.34457 0.9334              
## Total      10  2.51186 1.0000              
## 
## $MowRx_vs_Harvest
##            Df SumOfSqs      R2      F Pr(>F)  
## Treat_Type  1  0.72529 0.32578 3.3823  0.014 *
## Residual    7  1.50107 0.67422                
## Total       8  2.22636 1.00000                
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## $MowRx_vs_Control
##            Df SumOfSqs      R2      F Pr(>F)  
## Treat_Type  1  0.84147 0.41918 4.3303  0.012 *
## Residual    6  1.16594 0.58082                
## Total       7  2.00741 1.00000                
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## $Harvest_vs_Control
##            Df SumOfSqs      R2      F Pr(>F)  
## Treat_Type  1  0.58418 0.21102 2.4072  0.023 *
## Residual    9  2.18412 0.78898                
## Total      10  2.76830 1.00000                
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## attr(,"class")
## [1] "pwadstrata" "list"
#significant: SpringRx vs. MowRx; SpringRx vs. Harvest (borderline at 0.051); MowRx vs. Harvest; MowRx vs Control; Harvest vs Control

Indicator species analysis

library(labdsv)

ma.meta.data_veg$Treat_Group <- NA

ma.meta.data_veg$Treat_Group <- ifelse( ma.meta.data_veg$Treat_Type == "FallRx", 1, ma.meta.data_veg$Treat_Group)

ma.meta.data_veg$Treat_Group <- ifelse( ma.meta.data_veg$Treat_Type == "MowRx", 2, ma.meta.data_veg$Treat_Group)

ma.meta.data_veg$Treat_Group<- ifelse( ma.meta.data_veg$Treat_Type == "SpringRx", 3, ma.meta.data_veg$Treat_Group)

ma.meta.data_veg$Treat_Group<- ifelse( ma.meta.data_veg$Treat_Type == "Harvest", 4, ma.meta.data_veg$Treat_Group)

ma.meta.data_veg$Treat_Group<- ifelse( ma.meta.data_veg$Treat_Type == "Control", 5, ma.meta.data_veg$Treat_Group)

mali_isa <- indval(mali5_avg, ma.meta.data_veg$Treat_Group)

summary(mali_isa)
##      cluster indicator_value probability
## QUPR       2          0.8549       0.001
## KAAN       2          0.7534       0.012
## RUSP       2          0.7097       0.006
## SMGL       4          0.6896       0.009
## 
## Sum of probabilities                 =  4.689 
## 
## Sum of Indicator Values              =  6.68 
## 
## Sum of Significant Indicator Values  =  3.01 
## 
## Number of Significant Indicators     =  4 
## 
## Significant Indicator Distribution
## 
## 2 4 
## 3 1
gr <- mali_isa$maxcls[mali_isa$pval <= 0.05]
iv <- mali_isa$indcls[mali_isa$pval <= 0.05]
pv <- mali_isa$pval[mali_isa$pval <= 0.05]
fr <- apply(mali5_avg > 0, 2, sum)[mali_isa$pval <= 0.05]
fridg <- data.frame(group=gr, indval=iv, pvalue=pv, freq=fr)
fridg <- fridg[order(fridg$group, -fridg$indval),]

print(fridg)
##      group    indval pvalue freq
## QUPR     2 0.8549332  0.001    6
## KAAN     2 0.7534400  0.012   10
## RUSP     2 0.7096551  0.006    7
## SMGL     4 0.6896051  0.009    6
# 1 is FallRx
# 2 is MowRx
# 3 is SpringRx
# 4 is Harvest
# 5 is Control

MA_LI MowRx indicators: QUPR, KAAN, RUSP

MA_LI Harvest indicator: SMGL